@using CodeGenerator
@using RazorLight
@using BXJG.Common;
@using BXJG.Common.Extensions;
@inherits TemplatePage<ExecuteContext>
@{
    DisableEncoding = true;//禁止html编码，因为我们是做代码生成器
}
using @(Model.Model.ApplicationShareNamespace);
using Abp.Application.Navigation;

namespace @(Model.App.ApplicationProjectName)
{
    @* 命名空间和类名必须固定 *@
    public partial class @(Model.App.Name)NavigationProvider
    {
        @* 必须以CodeGenerator打头，因为主程序反射调用的 *@
        public void CodeGenerator@(Model.Model.Name)(INavigationProviderContext context)
        {
            object parentMenu = default;
            const string currMenuName = "@(Model.Model.ParentMenuName)";
            foreach (var item in context.Manager.Menus)
            {
                if (item.Key.Equals(currMenuName, StringComparison.OrdinalIgnoreCase))
                    parentMenu = item.Value;
                else
                    parentMenu = item.Value.RecursionFindDown(currMenuName);
            }
            if (parentMenu == default)
                parentMenu = context.Manager.MainMenu;

            var menuItem = new MenuItemDefinition(@(Model.Model.PermissionNameGetConst),
                                                  @(Model.Model.PermissionNameGetConst).Get@(Model.App.Name)LocalizableString(),
                                                  icon: "@(Model.Model.Icon)",
                                                  url: "/@(Model.Model.Name)",
                                                  permissionDependency: new SimplePermissionDependency(@(Model.Model.PermissionNameGetConst)));

            if (parentMenu is MenuDefinition m0)
            {
                m0.AddItem(menuItem);
            }
            else
            {
                (parentMenu as MenuItemDefinition).AddItem(menuItem);
            }
        }
    }
}